$(function(){
	loadData();
});


function changeAcount(newValue, oldValue) {
	if (oldValue && newValue) {
		frame.window.refresh({
			acountId : newValue
		});
	}
}

function loadData(){
	var acountId = $("#acountId").combobox("getValue");
	$.ajax("./modelconfig.json",{
		data:{acountId:acountId},
		mask:true,
		success: function(data){
			if(data.acount){
				$('#ff').form('load', data.acount);
				$('#dg').datagrid('loadData', data.params);
			}
		}
	});
}

function click_save_model(){
	$('#ff').form('ajaxSubmit',{ 
		url: "./savemodelconfig.json",
		type: "post",
		success: function(){
			frame.window.refresh();
		}
	});
}

function click_delete_model() {
	$.messager.confirm('确认', '您确认想要删除模型吗？',
		function(r) {
			if (r) {
				$('#ff').form('ajaxSubmit', {
					url : "./deletemodelconfig.json",
					type : "post",
					success : function() {
						frame.window.refresh();
					}
				});
			}
		}
	);
}

function click_run_all(){
	$.post("./backtest.json");
}

function click_run() {
	var selectRow = $('#dg').datagrid("getSelected");
	if (selectRow) {
		$.post("./backtest.json", selectRow);
	} else {
		alert("请选择账户");
	}
}

function click_copy() {
	$.ajax("./copyacount.json", {
		mask : true,
		type : 'post',
		success : function(data){
			if(data.sucesse){
				loadData();
			}
		}
	});
}